/* (c)2010-2012 Andrea Caltroni (andrea.caltroni@pd.infn.it), INFN (www.infn.it)
 *
 * This file is part of the IGI Survey Portlet (from here on shortened to IGISP).
 * IGISP is free software: you can redistribute it and/or modify it 
 * under the terms of the GNU General Public License as published by the Free 
 * Software Foundation, either version 3 of the License, or (at your option) any 
 * later version.
 *
 * IGISP is distributed in the hope that it will be useful, but WITHOUT ANY 
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
 * A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with IGISP. If not, see <http://www.gnu.org/licenses/>.
 */
package it.infn.grid.liferay.survey.modules.admin.web;

import org.ajm.spring.core.model.AbstractPersistentEntity;
import org.ajm.spring.survey.modules.admin.model.ReportFormat;
import org.ajm.spring.survey.modules.admin.model.Survey;
import org.apache.commons.lang.builder.CompareToBuilder;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;

/**
 * The command object used to bind the values in the form to export a survey report.
 * 
 * @author Andrea Caltroni, andrea.caltroni@pd.infn.it, INFN
 */
public class ExportReportCommand extends AbstractPersistentEntity implements Comparable<ExportReportCommand> {
    
    // ------------------------------------------------------------------------|
    // --- CONSTANTS ----------------------------------------------------------|
    // ------------------------------------------------------------------------|

    private static final long serialVersionUID = -1165044916080566920L;

    // ------------------------------------------------------------------------|
    // --- CLASS VARIABLES ----------------------------------------------------|
    // ------------------------------------------------------------------------|
    
    // ------------------------------------------------------------------------|
    // --- INSTANCE VARIABLES -------------------------------------------------|
    // ------------------------------------------------------------------------|
    
    private Survey survey;
    
    private ReportFormat reportFormat;
    
    // ------------------------------------------------------------------------|
    // --- CONSTRUCTORS -------------------------------------------------------|
    // ------------------------------------------------------------------------|

    /**
     * Default empty constructor.
     */
    public ExportReportCommand() {
        
        super();
    }

    // ------------------------------------------------------------------------|

    /**
     * @param survey 
     */
    public ExportReportCommand(Survey survey) {
        
        super();
        if (survey != null) this.setSurvey(survey);
    }

    // ------------------------------------------------------------------------|
    // --- CLASS METHODS ------------------------------------------------------|
    // ------------------------------------------------------------------------|

    // ------------------------------------------------------------------------|
    // --- INSTANCE METHODS ---------------------------------------------------|
    // ------------------------------------------------------------------------|
    
    /**
     * Adds the ability to perform order comparisons.
     * 
     * @see java.lang.Comparable#compareTo(java.lang.Object)
     */
    public int compareTo(ExportReportCommand that) {
        
        return new CompareToBuilder()

        .append(this.getDateCreated(), that.getDateCreated())
        
        .append(this.getSurvey(), that.getSurvey())
        
        .append(this.getReportFormat(), that.getReportFormat())
        
        .toComparison();

    }
    
    // ------------------------------------------------------------------------|
    
    /**
     * Implements the concept of logical equality for this object.
     *
     * @see java.lang.Object#hashCode()
     * @see java.lang.Object#equals(Object)
     */
    @Override
    public boolean equals(Object object) {

        if (this == object)
            return true;

        if (!(object instanceof ExportReportCommand)) {
            return false;
        }

        final ExportReportCommand that = (ExportReportCommand) object;

        return new EqualsBuilder()
        
        .append(this.getSurvey(), that.getSurvey())

        .append(this.getReportFormat(), that.getReportFormat())

        .isEquals();
    }

    // ------------------------------------------------------------------------|

    /**
     * Compute the hash code for this object. This is necessary when overriding
     * equals since equal objects must have equal hash codes.
     * 
     * @see java.lang.Object#hashCode()
     * @see java.lang.Object#equals(Object)
     */
    @Override
    public int hashCode() {

        return new HashCodeBuilder(-83574467, 150340475)

        .append(this.getSurvey())

        .append(this.getReportFormat())

        .toHashCode();
    }

    // ------------------------------------------------------------------------|

    /**
     * Obtain a string representation of this object.
     *
     * @see java.lang.Object#toString()
     */
    @Override
    public String toString() {

        return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)

        .append("survey", this.getSurvey())

        .append("report format", this.getReportFormat())

        .toString();
    }

    // ------------------------------------------------------------------------|

    /**
     * @return the reportFormat
     */
    public ReportFormat getReportFormat() {
        return reportFormat;
    }

    // ------------------------------------------------------------------------|

    /**
     * @param reportFormat the reportFormat to set
     */
    public void setReportFormat(ReportFormat reportFormat) {
        this.reportFormat = reportFormat;
    }

    // ------------------------------------------------------------------------|

    /**
     * @return the survey
     */
    public Survey getSurvey() {
        return survey;
    }

    // ------------------------------------------------------------------------|

    /**
     * @param survey the survey to set
     */
    public void setSurvey(Survey survey) {
        this.survey = survey;
    }

    // ------------------------------------------------------------------------|
    
}
